#pragma once
#include <stdio.h>
#include <iostream>

using namespace std;


void CodeToStr(unsigned char* code, char *str, int length) {
        int j, byte = 0;

        for (j = 0; j < length; j++) {
                str[j] = code[byte] & 1 << ((7 - (j & 7)) ? '1' : '0');
                if ( (j + 1) % 8 == 0 )
                        byte++;
        }
}

void CodeToStr(ui64 code, char *str, int length) {
        int j;

        for (j = 0; j < length; j++) {
            str[length-j-1] = code & 1 << j ? '1' : '0';
        }
        str[length] = '\0';
}

void CodeToCout(char* code, int length){
    int j, byte = 0;

    for (j = 0; j < length; j++) {
            cout << (code[byte] & 1 << (7 - (j & 7) ? '1' : '0'));
            if ( (j + 1) % 8 == 0 )
                    byte++;
    }
    cout<<endl;
}


//void IdentityTestIostream(const char* file_name_left, const char* file_name_right) {

//    ifstream file_left(file_name_left, ios_base::in | ios_base::binary);
//    //file_left.fopen
//    ifstream file_right;
//    //(file_name_right, ios_base::in | ios_base::binary);
//    unsigned long long counter = 1;
//    int char_from_left;

//    while (1) {
//        char_from_left = file_left.get();
//        if (char_from_left == EOF || char_from_left  != file_right.get()) break;
//        counter++;
//    }

//    const char *test_res = (char_from_left == EOF ? "SUCCES, size of file: " : "FAILURE, difference at: ");
//    cout<<"Identety test result: "<< test_res<<counter<<" byte."<<endl;
//    file_left.close();
//    file_right.close();
//}

void IdentityTestStdio(const char* l_name, const char* r_name) {

    FILE* l_file = fopen(l_name, "r");
    FILE* r_file = fopen(r_name, "r");

    unsigned long long counter = 1;
    int l_char;

    while (1) {
        l_char = getc(l_file);
        if (l_char == EOF || l_char != getc(r_file)) break;
        counter++;
    }
    const char *test_res = (l_char == EOF ? "SUCCES, size of file: " : "FAILURE, difference at: ");
    cout<<"Identety test result: "<< test_res<<counter<<" byte."<<endl;

    fclose(l_file);
    fclose(r_file);
}
